import type { IResData } from '../indexTypes';
import { root } from '../apiRoot';
import { defHttp } from '@/utils/http';
import type {
  ApplyTemplateListResult,
  ByIdApplyExplainResult,
  CustomFormGetStageListResult,
  CustomModuleTypeResult,
  MemberApplyFormAddData,
  MemberApplyFormAddResult,
  MemberApplyResult,
  MemberInfoResult,
  MemberTypeGetListItem,
  PolicyDetailResult,
  ReportInfoResult,
  ServiceProviderResult,
  StageFormResult,
  TotalAwardResult,
  PayWayData,
} from './types';
import type { ApplyTypeEnum } from '@/enums/membershipEnum';

export const Api = {
  applyTemplateList: root + 'member-apply-form/getApplyTemplateList',
  byIdApplyExplain: root + 'member-apply-form/getByIdApplyExplain',
  memberApply: root + 'member-apply-form/getMemberApply',
  customFormGetStageList: root + 'custom-form/getStageList',
  stageForm: root + 'custom-form/getStageById',
  memberTypeGetList: root + 'memberType/getList',
  memberApplyFormAdd: root + 'member-apply-form/add',
  getAuditUserList: root + 'member-apply-form/getAuditUserList',
  updateAuditStatus: root + 'member-apply-form/updateAuditStatus',
  getMemberInfo: root + 'member-info/getMemberInfo',
  customModuleType: root + 'member-info/custom-module-type/list',
  updateMemberInfo: root + 'member-info/updateMemberInfo',
  reportInfo: root + 'chacewang/getReport',
  policyDetail: root + 'chacewang/getPolicyDetail',
  totalAward: root + 'chacewang/getTotalAward',
  serviceProvider: root + 'serviceProvider/getServiceProvider',

  paymentInfo: root + 'order/member-paymenrecord/payFees/getMemberApplyById',
  renewInfo: root + 'order/member-paymenrecord/renewInfo',
  paymentExport: root + 'order/member-paymenrecord/paymentExport',
  getPayConfig: root + 'order/member-paymenrecord/getOrgPaymenconfigVo',
  createOrder: root + 'order/member-paymenrecord/createOrder',
  paymentVoucher: root + 'order/member-paymenrecord/createOfflineTransactionOrder',
  resetSubmit: root + 'order/member-paymenrecord/resubmit',
  membershipFormPdf: root + 'member-info/customPdf',
  /** 入会申请表下载地址 */
  memberApplyFormPdf: root + 'member-apply-form/customPdf'
};

/**
 * @description 获取申请入会类型模版
 * @date 28/07/2022
 * @export
 */
export function applyTemplateList() {
  return defHttp.get<ApplyTemplateListResult[]>({
    url: Api.applyTemplateList,
  });
}

/**
 * @description 获取申请须知
 * @date 30/07/2022
 * @export
 * @param {number} id 申请模版id 个人 / 单位
 */
export function byIdApplyExplain(id: number) {
  return defHttp.get<ByIdApplyExplainResult>({
    url: Api.byIdApplyExplain + `/${id}`,
  });
}

/**
 * @description 获取我当前阶段的申请内容
 * @date 30/07/2022
 * @export
 */
export function memberApply() {
  return defHttp.get<MemberApplyResult>({
    url: Api.memberApply,
  });
}

/**
 * @description 获取申请阶段
 * @date 30/07/2022
 * @export
 * @param {number} id
 */
export function customFormGetStageList(id: number) {
  return defHttp.get<CustomFormGetStageListResult[]>({
    url: Api.customFormGetStageList + `/${id}`,
  });
}

/**
 * @description 获取当前阶段的表单模板
 * @date 30/07/2022
 * @export
 * @param {number} id 阶段id
 */
export function stageForm(id: number) {
  return defHttp.get<StageFormResult>({
    url: Api.stageForm + `/${id}`,
  });
}

/**
 * @description 根据表单项绑定字段获取远程数据
 * @date 30/07/2022
 * @export
 * @param {string[]} keyword 查询字段
 */
export function memberTypeGetList(
  keyword: string[],
  sceneType?: 'memberApply',
  memberType?: ApplyTypeEnum,
) {
  return defHttp.get<{ [x: string]: MemberTypeGetListItem[] }>({
    url: Api.memberTypeGetList + `/${keyword.join(',')}`,
    data: {
      sceneType,
      memberType,
    },
  });
}

/**
 * @description 提交入会申请数据
 * @date 30/07/2022
 * @export
 * @param {MemberApplyFormAddData} data
 */
export function memberApplyFormAdd(data: MemberApplyFormAddData) {
  return defHttp.post<MemberApplyFormAddResult>({
    url: Api.memberApplyFormAdd,
    data,
  });
}

/**
 * @description 获取缴费详情-入会处
 * @date 11/10/2022
 * @export
 * @param {*} id 申请ID
 */
export function paymentInfo(id: number) {
  return defHttp.get({
    url: Api.paymentInfo + `/${id}`,
  });
}

/**
 * @description 获取续费详情-入会处
 * @date 23/02/2023
 * @export
 */
export function renewInfo() {
  return defHttp.get({
    url: Api.renewInfo,
  });
}

/**
 * @description 获取可支付方式
 * @date 22/02/2023
 * @export
 */
export function getPayConfig() {
  return defHttp.get<PayWayData>({
    url: Api.getPayConfig,
  });
}

/**
 * @description 选择在线支付-创建订单
 * @date 23/02/2023
 * @export
 * @param {*} id 申请ID
 */
export function createPayOrder(id: number) {
  return defHttp.post({
    url: Api.createOrder + `/${id}`,
  });
}

/**
 * @description 选择转账-提交凭证
 * @date 23/02/2023
 * @export
 */
export function upPaymentVoucher(data: any) {
  return defHttp.post({
    url: Api.paymentVoucher,
    data,
  });
}

/**
 * @description 转账凭证驳回-重新提交
 * @date 23/02/2023
 * @export
 */
export function resetSubmit(id: number) {
  return defHttp.post({
    url: Api.resetSubmit + `/${id}`,
  });
}

/**
 * @description
 * @date 12/10/2022
 * @export
 * @param {*} level 根据阶段获取审核人列表
 */
export function getAuditUserList(level: number) {
  return defHttp.get({
    url: Api.getAuditUserList + `/${level}`,
  });
}

/**
 * @description 重置入会资料,重新申请
 * @date 12/10/2022
 * @export
 */
export function updateAuditStatus() {
  return defHttp.post({
    url: Api.updateAuditStatus,
  });
}

/**
 * @description 获取入会资料信息
 * @date 13/10/2022
 * @export
 */
export function getMemberInfo() {
  return defHttp.get<MemberInfoResult>({
    url: Api.getMemberInfo,
  });
}

/**
 * @description 获取入会资料的阶段
 * @date 13/10/2022
 * @export
 */
export function customModuleType() {
  return defHttp.get<CustomModuleTypeResult[]>({
    url: Api.customModuleType,
  });
}

/**
 * @description 入会资料提交数据
 * @date 13/10/2022
 * @export
 * @param {*} data
 */
export function updateMemberInfo(data: any) {
  return defHttp.post({
    url: Api.updateMemberInfo,
    data,
  });
}

/**
 * @description 获取政策服务报告
 * @date 13/10/2022
 * @export
 * @param {*} name
 */
export function reportInfo(name: string) {
  return defHttp.get<ReportInfoResult>({
    url: Api.reportInfo,
    data: { name },
  });
}

/**
 * @description 获取政策详情
 * @date 13/10/2022
 * @export
 * @param {*} name
 */
export function policyDetail(id: string) {
  return defHttp.get<PolicyDetailResult>({
    url: Api.policyDetail,
    data: { id },
  });
}

/**
 * @description 获取预估申报金额
 * @date 13/10/2022
 * @export
 * @param {*} name
 */
export function totalAward(name: string) {
  return defHttp.get<TotalAwardResult>({
    url: Api.totalAward,
    data: { name },
  });
}

/**
 * @description 获取服务商联系方式
 * @date 13/10/2022
 * @export
 * @param {*} type
 */
export function serviceProvider(type: number) {
  return defHttp.get<ServiceProviderResult>({
    url: Api.serviceProvider,
    data: { type },
  });
}
